package com.service.impl;

import com.bean.entity.Street;
import com.bean.pojo.PageAssistant;
import com.dao.StreetMapper;
import com.service.StreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:31
 * 街道
 */
@Service
public class StreetServiceImpl implements StreetService {

    @Autowired
    private StreetMapper streetMapper;
    @Override
    public int save(Street t) throws Exception {
        int insert = streetMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增街道信息失败");
    }
    @Override
    public int remove(Street t) throws Exception {
        int delete = streetMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除街道信息失败");
    }
    @Override
    public int modify(Street t) throws Exception {
        int update = streetMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改街道信息失败");
    }
    @Override
    public Street unique(Street t) throws Exception {
        List<Street> streetList = streetMapper.select(t);
        if (streetList.size() !=1) throw new Exception("无此街道信息");
        return streetList.get(0);
    }
    @Override
    public List<Street> query(Street t) {
        return streetMapper.select(t);
    }
    @Override
    public PageAssistant<Street> queryByPage(Map<String, Object> map, PageAssistant<Street> pa) {
        pa.setCount(streetMapper.selectCount(map));
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        pa.setItems(streetMapper.selectByPage(map));
        return pa;
    }
}
